package org.ch00.test02;

import java.util.List;
import java.util.Random;

/*
 *
 *@author XCH
 *@date 2025 - 03 - 03
 *
 */
public class People{
    public void pay() {
        // 动态管理支付方式，便于扩展
        List<PaymentMethod> paymentMethods = List.of(
                new ZhiFuBao(),
                new WeiXin()
        );

        // 随机选择一个支付方式
        PaymentMethod method = getRandomPaymentMethod(paymentMethods);
        method.pay();
    }

    private PaymentMethod getRandomPaymentMethod(List<PaymentMethod> methods) {
        if (methods.isEmpty()) {
            throw new IllegalArgumentException("支付方式列表不能为空");
        }
        Random random = new Random();
        return methods.get(random.nextInt(methods.size()));
    }
}
